package com.taoye.cloud.provider.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class TestController {
    
    @Value("${test.value}")
    private String value;
    @Value("${server.port}")
    private String port;
    
    @GetMapping(value = "test",produces ="text/html;charset=utf-8")
    public String test() {
        return "<div style='color:red'>我返回了</div>";
    }
    
    @GetMapping(value = "test/get",produces ="text/html;charset=utf-8")
    public String testGet() {
        return "<div style='color:red'>配置的值为:"+value+",端口号为:"+port+"</div>";
    }
    
    @GetMapping("test1/{param}")
    public String test1(@PathVariable String param) {
        System.out.println("收到请求："+param);
        
        return "我返回啦";
    }
    
    @PostMapping("/test/post")
    public String post(@RequestBody Map<String, Object> params) {
        System.out.println(params);
        return "{\"aaa\":111,\"bbb\":222}";
    }
    
}
